//
//  LeftViewController.m
//  Eath
//
//  Created by yuhaya on 14-8-23.
//  Copyright (c) 2014年 yuhaya. All rights reserved.
//

#import "LeftViewController.h"
#import "AboutViewController.h"
#import "LoginViewController.h"
#import "LeftTableCell.h"

@interface LeftViewController ()

@end

@implementation LeftViewController

static NSString *cellId = @"list_cell";

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.dataSource = @{
                            @"登录":[LoginViewController class],
                            @"关于我们":[AboutViewController class]
                            };
        self.dataKey = @[@"登录",@"关于我们"];
    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataKey count];
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    LeftTableCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    cell.item.text = self.dataKey[indexPath.row];
    cell.selectedBackgroundView.backgroundColor = [UIColor greenColor];
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    LeftTableCell * selectCell = (LeftTableCell *)[tableView cellForRowAtIndexPath:indexPath];
//    selectCell.opaque = NO;
//    selectCell.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
    
    NSString *key = self.dataKey[indexPath.row];
    
    [self.delegate changeViewController:self.dataSource[key] byKey:key];
    [self.drawerController closeDrawerAnimated:YES completion:^(BOOL finished) {
        
    }];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UINib *nib = [UINib nibWithNibName:@"LeftTableCell" bundle:nil];
    [self.tableList registerNib:nib forCellReuseIdentifier:cellId];
    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
